import { PrismaClient } from '@prisma/client'
import bcrypt from 'bcrypt'

const prisma = new PrismaClient()

async function main() {
  // 清除现有数据
  await prisma.user.deleteMany()

  // 创建测试用户
  const users = [
    {
      email: 'admin@example.com',
      password: await bcrypt.hash('123456', 10)
    },
    {
      email: 'user@example.com',
      password: await bcrypt.hash('123456', 10)
    }
  ]

  for (const user of users) {
    await prisma.user.create({
      data: user
    })
  }

  // // 添加地区测试数据
  // const regions = [
  //   // 市级
  //   { code: '3701', name: '济南市', level: 1, parentCode: null },
  //   { code: '3302', name: '宁波市', level: 1, parentCode: null },
    
  //   // 县级
  //   { code: '370106', name: '西湖区', level: 2, parentCode: '3701' },
  //   { code: '370104', name: '江干区', level: 2, parentCode: '3701' },
  //   { code: '330203', name: '海曙区', level: 2, parentCode: '3302' },
    
  //   // 街道
  //   { code: '370106001', name: '蒋村街道', level: 3, parentCode: '370106' },
  //   { code: '370106002', name: '转塘街道', level: 3, parentCode: '370106' },
  //   { code: '370104001', name: '笕桥街道', level: 3, parentCode: '370104' },
    
  //   // 村居
  //   { code: '370106001001', name: '蒋村社区', level: 4, parentCode: '370106001' },
  //   { code: '370106001002', name: '永福社区', level: 4, parentCode: '370106001' },
  //   { code: '370106002001', name: '转塘村', level: 4, parentCode: '370106002' },
  // ]

  // // 创建地区数据
  // for (const region of regions) {
  //   await prisma.region.create({
  //     data: region
  //   })
  // }

  // 添加组织测试数据
  const organizations = [
    // 党组织
    {
      name: '济南市委',
      code: 'PARTY_3701',
      type: 'PARTY' as const,
      regionCode: '3701',
      level: 1,
      description: '中共济南市委员会',
      leader: '张三'
    },
    {
      name: '西湖区委',
      code: 'PARTY_370106',
      type: 'PARTY' as const,
      regionCode: '370106',
      parentId: 1,
      level: 2,
      description: '中共西湖区委员会',
      leader: '李四'
    },
    
    // 经济组织
    {
      name: '济南市实业集团',
      code: 'ECO_3701_01',
      type: 'ECONOMIC' as const,
      regionCode: '3701',
      level: 1,
      description: '济南市属国有企业',
      leader: '王五'
    },
    {
      name: '西湖区产业投资集团',
      code: 'ECO_370106_01',
      type: 'ECONOMIC' as const,
      regionCode: '370106',
      parentId: 3,
      level: 2,
      description: '西湖区属国有企业',
      leader: '赵六'
    },
    
    // 社会组织
    {
      name: '济南市工商联',
      code: 'SOC_3701_01',
      type: 'SOCIAL' as const,
      regionCode: '3701',
      level: 1,
      description: '济南市工商业联合会',
      leader: '钱七'
    },
    {
      name: '西湖区工商联',
      code: 'SOC_370106_01',
      type: 'SOCIAL' as const,
      regionCode: '370106',
      parentId: 5,
      level: 2,
      description: '西湖区工商业联合会',
      leader: '孙八'
    }
  ]

  for (const org of organizations) {
    await prisma.organization.create({
      data: org
    })
  }

  console.log('种子数据已创建')
}

main()
  .catch((e) => {
    console.error(e)
    process.exit(1)
  })
  .finally(async () => {
    await prisma.$disconnect()
  }) 